package cn.didi.feidi.androidorder.assembly;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by jinxiong on 2017/8/29.
 */
public class FeiDiKeyboardTextView extends android.support.v7.widget.AppCompatTextView implements View.OnClickListener {

    private Callback callback;

    public FeiDiKeyboardTextView(Context context) {
        this(context, null);

    }

    public FeiDiKeyboardTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FeiDiKeyboardTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    public Callback getCallback() {
        return callback;
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    private void initView() {
        setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (callback != null) {
            callback.callback(getText().toString().charAt(0));
        }
    }

    public interface Callback {

        void callback(char number);
    }
}
